package cn.itcast.Converter;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StringToDataConverter implements Converter<String,Date> {
    @Override
    public Date convert(String source) {
        SimpleDateFormat simpleDateFormat=null;
        Date data=null;
        try {
            if (source.contains("/")){
                simpleDateFormat=new SimpleDateFormat("yyyy/MM/hh");
            }else {
                simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            }
            data=simpleDateFormat.parse(source);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return data;
    }
}
